package cn.wolfcode.trip.admin.controller;


import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("strategyCatalog")
public class StrategyCatalogController {

    @Autowired
    private IStrategyCatalogService strategyCatalogService;



    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") StrategyCatalogQueryObject qo){

        model.addAttribute("result", strategyCatalogService.queryForList(qo));
        return "strategy/catalog";
    }


    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate( StrategyCatalog catalog){
        JSONResult result = new JSONResult();
        try {

            if (catalog.getId()!=null){
                strategyCatalogService.update(catalog);
            }else {
                strategyCatalogService.save(catalog);
            }
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
    @RequestMapping("listByStrategyId")
    @ResponseBody
    public List<StrategyCatalog> listByStrategyId(Long id){


            return strategyCatalogService.listByStrategyId(id);

    }

}

